<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var MacroCommand = function() {
            return {
                commandList: [],
                add: function(command) {
                    this.commandList.push(command)
                },
                execute: function() {
                    for (let command of this.commandList) {
                        command.execute()
                    }
                }
            }
        }
// 创建对象
// 工蚁 4
var antWork_1 = { execute: function() { console.log("工蚁：服侍蚁后搬家...") } }
var antWork_2 = { execute: function() { console.log("工蚁：服侍蚁后搬家...") } }
var antWork_3 = { execute: function() { console.log("工蚁：服侍蚁后搬家...") } }
var antWork_4 = { execute: function() { console.log("工蚁：服侍蚁后搬家...") } }

// 兵蚁 2
var antSoldier_1 = {
  execute: function() { console.log("兵蚁: 指挥交通...") }
}
var antSoldier_2 = {
  execute: function() { console.log("兵蚁: 指挥交通...") }
}
// 繁殖蚁 2
var antWoman_1 = {
  execute: function() { console.log("繁殖蚁: 走在大部队前面...") }
}
var antWoman_2 = {
  execute: function() { console.log("繁殖蚁: 走在大部队前面...") }
}
// 蚁后
var antQueen =  MacroCommand()
antQueen.add(antWork_1)
antQueen.add(antWork_2)
antQueen.add(antWork_3)
antQueen.add(antWork_4)


var moveHome = MacroCommand()

moveHome.add(antSoldier_1);
moveHome.add(antSoldier_1);
moveHome.add(antWoman_1);
moveHome.add(antWoman_2);
moveHome.add(antQueen);

moveHome.execute()


    </script>
</body>
</html>